using UnityEngine;
using System.Collections;

//(c) 2011 VDZ
//made for Ludum Dare 22
//
//Licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0) 
//
//You are free:
//# to Share — to copy, distribute and transmit the work
//# to Remix — to adapt the work 
//
//Under the following conditions:
//# Attribution — You must attribute the work in the manner specified by the author or licensor
//      (but not in any way that suggests that they endorse you or your use of the work).
//# Noncommercial — You may not use this work for commercial purposes. 
//
//With the understanding that: 
//# Waiver — Any of the above conditions can be waived if you get permission from the copyright holder. 
//# Public Domain — Where the work or any of its elements is in the public domain under applicable law,
//      that status is in no way affected by the license. 
//# Other Rights — In no way are any of the following rights affected by the license:
//  * Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
//  * The author's moral rights;
//  * Rights other persons may have either in the work itself or in how the work is used, such as publicity
//      or privacy rights.

public class MessageBox {
    public float left;
    public float top;
    public float height;
    public float width;
    public string message;
    public bool ending = false;
    public string header = "";
    public string story = "";

    public MessageBox(int left, int top, int width, int height, string message)
    {
        this.left = left;
        this.top = top;
        this.width = width;
        this.height = height;
        this.message = message;
    }

    public MessageBox(string message)
    {
        this.left = 30;
        this.top = 30;
        this.width = 40;
        this.height = 15;
        this.message = message;
    }

    public MessageBox(string header, string story, bool ending) //Ending messagebox
    {
        this.ending = ending;
        this.header = header;
        this.story = story;

        this.left = 10;
        this.top = 10;
        this.width = 80;
        this.height = 55;
        this.message = "";
    }

    public void Display()
    {
        string buttonlabel = "Ok";

        if (ending) buttonlabel = "GAME OVER";

        GUI.Box(new Rect(UnityMain.ConvertX(left), UnityMain.ConvertY(top),
            UnityMain.ConvertX(width), UnityMain.ConvertY(height)), "", UnityMain.windowstyle);
        GUI.TextArea(new Rect(UnityMain.ConvertX(left), UnityMain.ConvertY(top),
            UnityMain.ConvertX(width), UnityMain.ConvertY(height - 10f)), message, UnityMain.messageBoxStyle);
        if (GUI.Button(new Rect(
            UnityMain.ConvertX(left + (width / 2) - 10),
            UnityMain.ConvertY((top + height) - 7.5f),
            UnityMain.ConvertX(20),
            UnityMain.ConvertY(5)), buttonlabel, UnityMain.buttonStyle))
        {
            if (!ending)
            {
                UnityMain.messageBox = null;
            }
            else
            {
#if UNITY_WEBPLAYER
                //GameMain.FullReset();
                //Application.LoadLevel("Game");
                //Maybe I will fix this some day
#else
                Application.Quit();
#endif
            }
        }

        if (header != "")
        {
            GUI.TextArea(new Rect(UnityMain.ConvertX(left), UnityMain.ConvertY(top),
            UnityMain.ConvertX(width), UnityMain.ConvertY(7.5f)), header, UnityMain.headerStyle);
            GUI.TextArea(new Rect(UnityMain.ConvertX(left), UnityMain.ConvertY(top + 7.5f),
            UnityMain.ConvertX(width), UnityMain.ConvertY(37.5f)), story, UnityMain.storyStyle);
        }
    }
}
